package org.monkey.example.order.controller;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.monkey.common.constant.entity.Result;
import org.monkey.example.order.entity.form.OrderForm;
import org.monkey.example.order.entity.vo.OrderVo;
import org.monkey.example.order.provider.PayServiceProvider;
import org.monkey.example.order.service.OrderService;
import org.monkey.request.plugin.entity.TimeAnalyse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Data
@RestController
@RequestMapping("/order")
public class OrderController {

  @Value("${orderChinese}")
  private String orderChinese;

  @Value("${orderEnglish}")
  private String orderEnglish;

  @Autowired
  OrderService orderService;
  @Autowired
  PayServiceProvider payServiceProvider;

  @GetMapping
  @TimeAnalyse(tag = "order")
  public Result<String> order() {
    return Result.success(getOrderChinese() + ":" + getOrderEnglish());
  }

  @PostMapping
  @TimeAnalyse(tag = "orderSave")
  public Result<OrderVo> orderSave(@RequestBody OrderForm orderForm) {
    return Result.success(new OrderVo(orderService.save(orderForm)));
  }

  @GetMapping("/testFeignError")
  @TimeAnalyse
  public Result<String> testFeignError() {
    return Result.success(payServiceProvider.payError().getData());
  }
}
